/**
 * 
 */
package org.mediahouse.trac.util;

import java.io.PrintStream;
import java.util.Arrays;
import java.util.Iterator;

/**
 * @author Tin
 * @version %I%, %G%
 * 
 */
public final class debug {

    private static PrintStream OUT = System.out;

    /**
     * Default constructor. Not used by this class.
     */
    protected debug() {
    }

    /**
     * Outputs a message generated from the provided arguments to the debug
     * console at the point in the code that the trace is set. As much relevant
     * information as possible should be included in the trace's arguments.
     * 
     * @param args
     *            the arguments to output as text in the debug console.
     */
    public static void trace(final Object... args) {
        if (args == null || args.length == 0) return;
        else {
            final Iterator<Object> it = Arrays.asList(args).iterator();
            final StringBuilder msg = new StringBuilder("\n");
            msg.append("--------------------------------\n").append("INFO: ");
            while (it.hasNext()) {
                msg.append(it.next());
                if (it.hasNext()) msg.append(' ');
            }
            out(msg.toString());
        }
    }

    private static void out(final String msg) {
        OUT.print(msg);
    }

    /**
     * Sets or overrides the default output stream to which this class will send
     * any text designated for the debug console.
     * 
     * @param out
     *            the stream to output to instead of the default debug console.
     */
    public static void out(final PrintStream out) {
        OUT = out;
    }

}
